package com.typhoon.spring_jdbctemplate.consumer;

import com.typhoon.spring_jdbctemplate.util.ratelimit.RateLimiter;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class RedisRateLimiterConsumer {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-root.xml");
		context.start();

		String ipHost = "192.168.1.1";
		for(int i = 0 ;i < 10; i ++) {
			boolean result = RateLimiter.tryAccess(ipHost,1,1);
			if(result) {
				System.out.println("访问成功");
			} else {
				System.out.println("访问受限");
			}
		}
		context.stop();
	}
}
